package com.hushao.lims.weblims.service.impl;

import com.hushao.lims.weblims.domain.Module;
import com.hushao.lims.weblims.domain.Role;
import com.hushao.lims.weblims.domain.TeacherInfo;
import com.hushao.lims.weblims.repository.RoleRepository;
import com.hushao.lims.weblims.service.RoleService;
import com.hushao.lims.weblims.service.TeacherService;
import org.apache.commons.collections4.list.CursorableLinkedList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;

/**
 * @author 930588706
 * @date 18/1/16
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleRepository roleRepository;
    @Autowired
    private TeacherService teacherService;

    @Override
    public Set<Module> listModule(Integer teacherId) {
        List<Role>roles= teacherService.getById(teacherId).getRoles();
        //Set不可重复
        Set<Module> m=new HashSet<>();
        for (Role role:roles){
            m.addAll(role.getModules());
        }

        return m;
    }

    @Override
    public Role getById(int i) {
        return roleRepository.getOne(i);
    }

    @Override
    public List<Role> getRoles() {
        return roleRepository.findAll();
    }
}
